﻿using System;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Timers;

namespace KouakKore
{
    public class KouakIP
    {
        

        public static bool CheckPort(int port, IPAddress addr)
        {
            try
            {
                TcpClient TcpScan = new TcpClient();
                TcpScan.Connect(addr, port);
                return true;
            }

            catch (Exception e)
            {
                return false;
            }
        }

        public static IPAddress GetLocalIpAdress()
        {
            IPHostEntry IPHost = Dns.GetHostByName(Dns.GetHostName());
            return IPHost.AddressList[0];
        }

        public static IPAddress GetExternalIp()
        {
            string whatIsMyIp = "http://automation.whatismyip.com/n09230945.asp";
            WebClient wc = new WebClient();
            UTF8Encoding utf8 = new UTF8Encoding();
            string requestHtml = "";

            try
            {
                requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));
            }
            catch (WebException we)
            {
                Console.Write(we.ToString());
            }
            IPAddress externalIp = IPAddress.Parse(requestHtml);
            return externalIp;
        }
    }
}
